/**
 * Created by Laggo on 15/12/1.
 */
app.service('uploadService', ['Upload', 'SERVER_URL', '$q', function (Upload, SERVER_URL, $q) {
    this.upload = function (file) {
        var deferred = $q.defer();
        Upload.upload({
            url: SERVER_URL + '/back/file/upload',
            data: {file: file}
        }).then(function (resp) {
            deferred.resolve(resp.data.data);
        }, function (resp) {
            console.log('Error status: ' + resp.status);
        }, function (evt) {
            console.log(evt);
            var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
            console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
        });
        return deferred.promise;
    };
}]);
